package com.appleword.biz.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.appleword.common.annotation.Log;
import com.appleword.common.core.controller.BaseController;
import com.appleword.common.core.domain.AjaxResult;
import com.appleword.common.enums.BusinessType;
import com.appleword.biz.book.domain.ApplewordArticle;
import com.appleword.biz.book.service.IApplewordArticleService;
import com.appleword.common.utils.poi.ExcelUtil;
import com.appleword.common.core.page.TableDataInfo;

/**
 * 文章Controller
 * 
 * @author apple
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/book/article")
public class ApplewordArticleController extends BaseController
{
    @Autowired
    private IApplewordArticleService applewordArticleService;

    /**
     * 查询文章列表
     */
    @PreAuthorize("@ss.hasPermi('book:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplewordArticle applewordArticle)
    {
        startPage();
        List<ApplewordArticle> list = applewordArticleService.selectApplewordArticleList(applewordArticle);
        return getDataTable(list);
    }

    /**
     * 导出文章列表
     */
    @PreAuthorize("@ss.hasPermi('book:article:export')")
    @Log(title = "文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplewordArticle applewordArticle)
    {
        List<ApplewordArticle> list = applewordArticleService.selectApplewordArticleList(applewordArticle);
        ExcelUtil<ApplewordArticle> util = new ExcelUtil<ApplewordArticle>(ApplewordArticle.class);
        util.exportExcel(response, list, "文章数据");
    }

    /**
     * 获取文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('book:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applewordArticleService.selectApplewordArticleById(id));
    }

    /**
     * 新增文章
     */
    @PreAuthorize("@ss.hasPermi('book:article:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplewordArticle applewordArticle)
    {
        return toAjax(applewordArticleService.insertApplewordArticle(applewordArticle));
    }

    /**
     * 修改文章
     */
    @PreAuthorize("@ss.hasPermi('book:article:edit')")
    @Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplewordArticle applewordArticle)
    {
        return toAjax(applewordArticleService.updateApplewordArticle(applewordArticle));
    }

    /**
     * 删除文章
     */
    @PreAuthorize("@ss.hasPermi('book:article:remove')")
    @Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applewordArticleService.deleteApplewordArticleByIds(ids));
    }
}